import math


class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'Point({!r:},{!r:})'.format(self.x, self.y)

    def distance(self, x, y):
        return math.hypot(self.x - x, self.y - y)


if __name__ == '__main__':
    p = Point(2, 3)
    d = p.distance(0, 0)
    print(d)
    # 第2种方法
    d1 = getattr(p, 'distance')(0, 0)  # Calls p.distance(0, 0)
    print(d1)
    # 第3种方法
    import operator
    d2 = operator.methodcaller('distance',0,0)(p)
    print(d2)
    points = [
        Point(1, 2),
        Point(3, 0),
        Point(10, -3),
        Point(-5, -7),
        Point(-1, 8),
        Point(3, 2)
    ]
    points.sort(key= operator.methodcaller('distance',0,0))
    print(points)